package net.maku.jw.controller;

import com.alibaba.excel.util.StringUtils;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import net.maku.framework.common.utils.Result;
import net.maku.jw.entity.Course;
import net.maku.jw.entity.CourseList;
import net.maku.jw.entity.SysMember;
import net.maku.jw.service.SysMemberService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**\
 *
 */
@RestController
@RequestMapping("/jw")
@Tag(name = "VX")
@AllArgsConstructor
public class CourseController {
    private SysMemberService sysMemberService;

    /**\
     * 学期所有课表
     * @param sysMember
     * @return
     * @throws Exception
     */
    @PostMapping(value = "getstucourse")
    @Tag(name = "获取学生课程")
    public Result<CourseList> getStudentCourse(@RequestBody SysMember sysMember,@RequestParam(defaultValue = "2023-2024-1") String team) throws Exception {
        if (sysMember.getIsBind() == 0 && StringUtils.isNotBlank(sysMember.getToken())) {
            return Result.error("未绑定教务系统");
        }
        if (sysMember.getUseraccount()==null || team.isEmpty()) return Result.error("参数错误");
        List<Course> studentCourse = sysMemberService.getStudentCourse(sysMember,team);
        if (studentCourse.size() == 0) {
            return Result.error("课表获取失败");
        }
        return Result.ok(new CourseList(studentCourse));
    }

    /**
     * 默认参数值 如果不传  默认是第一周
     * @param sysMember
     * @return
     * @throws Exception
     */
    @GetMapping(value = "course")
    @Tag(name = "获取学生课程")
    public Result<CourseList> getStudentCourse(@RequestBody SysMember sysMember, @RequestParam(defaultValue = "1") int week,
                                               @RequestParam(defaultValue = "0") int flag, @RequestParam(defaultValue = "2023-2024-1") String team) throws Exception {
        if (sysMember.getIsBind() == 0 && StringUtils.isNotBlank(sysMember.getToken())) {
              return Result.error("未绑定教务系统");
        }
        if (sysMember.getUseraccount()==null || team.isEmpty()) return Result.error("参数错误");
        List<Course> studentCourse = sysMemberService.getStudentCourse(sysMember,week,flag,team);
        if (studentCourse.size() == 0) {
            return Result.error("课表获取失败");
        }
        return Result.ok(new CourseList(studentCourse));
    }


//    @PostMapping("/getstugrade")
//    @Tag(name = "获取学生成绩")
//    public GradeVo getStudentGrade(@RequestBody GetGradeInfo getGradeInfo) {
//        return studentService.getStudentGrade(getGradeInfo);
//    }



}
